//
//  Service+Coupon.m
//  gskin
//
//  Created by fengyn on 15/12/15.
//  Copyright © 2015年 lexingsoft. All rights reserved.
//

#import "Service+Coupon.h"
#import "DataManager.h"

@implementation ServiceManager(Coupon)
///查询用户优惠券
+ (void)getUserCouponWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/coupon/private/page";
    const int countPer = 20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer),
                                  @"userId":[DataManager sharedInstance].usersId};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        failure(dataObject);
    }];
}

///查询某商品可用的优惠券
+ (void)getAvailableCouponsWithProduct:(NSString *)productId price:(NSString *)price success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/coupon/private/usable";
    NSDictionary *parameterDict=@{@"productId":productId,
                                  @"orderPrice":price};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        failure(dataObject);
    }];
}

///分享优惠券成功
+ (void)putShareCouponsWithSequenceNBR:(NSString *)sequenceNBR success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = [NSString stringWithFormat:@"/coupon/private/share?couponId=%@",sequenceNBR];
    NSDictionary *parameterDict=nil;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
@end
